package com.meilingcloud.common.config;

import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Data
@Component
@ConfigurationProperties(prefix = "minio")
public class MinioConfig {
    /**
     * 域名
     */
    private String endpoint;
    /**
     * 端口
     */
    private int port;
    /**
     * 账户
     */
    private String accessKey;
    /**
     * 账户密码
     */
    private String secretKey;
    /**
     * 如果是true，则用的是https而不是http,默认值是true
     */
    private Boolean secure;
    /**
     * 默认存储桶
     */
    private String bucketName;

    @Bean
    public MinioClient getMinioClient() throws InvalidPortException, InvalidEndpointException {
        MinioClient minioClient = new MinioClient(endpoint, port, accessKey, secretKey, secure);
        return minioClient;
    }

}
